import simplejson as json
import os, sys, tempfile, zipfile, PIL, gifmaker
from PyQt4.QtGui import * 
from PyQt4.QtCore import * 
from sprite import *

class MapFile:
    def __init__(self, map):
        QObject.__init__(self)
        self.map = map

    def load(self, loadfile):
        zip = zipfile.ZipFile(str(loadfile), "r") 
        
        sprites = {}
        namelist = zip.namelist()
        for name in namelist:
            if name.startswith("sprites/"):
                sprites[name] = QImage()
                sprites[name].loadFromData(zip.read(name))
                
        tiles = {}
        namelist = zip.namelist()
        for name in namelist:
            if name.startswith("tiles/"):
                tiles[name] = QImage()
                tiles[name].loadFromData(zip.read(name))

        j = zip.read("brm.json")
        
        m = Map.fromjson(j, sprites, tiles)
        
        return s
